home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 May / Macworld (1999-05).dmg / Shareware World / Comms & Internet / OTSessionWatcher 2.0 / Developer Extras.sit / Developer Extras / Example / Example.c next >
MacBinary  |  1997-11-19  |  2.6 KB  |  [TEXT/CWIE]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacBinary (archive/macBinary).

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Wed Nov 19 11:49:45 1997, modified Wed Nov 19 11:49:45 1997, creator 'CWIE', type ASCII, 2011 bytes "Example.c" , at 0x85b 410 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[CWIE]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 09 45 78 61 6d 70 6c | 65 2e 63 00 00 00 00 00 |..Exampl|e.c.....|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 43 57 49 | 45 01 00 00 00 00 00 00 |.TEXTCWI|E.......|
|00000050| 00 00 00 00 00 07 db 00 | 00 01 9a b0 98 c9 29 b0 |........|......).|
|00000060| 98 c9 29 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |..).....|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 f2 d8 00 00 |........|........|
|00000080| 23 69 6e 63 6c 75 64 65 | 20 3c 4f 70 65 6e 54 72 |#include| <OpenTr|
|00000090| 61 6e 73 70 6f 72 74 2e | 68 3e 0d 23 69 6e 63 6c |ansport.|h>.#incl|
|000000a0| 75 64 65 20 3c 4f 70 65 | 6e 54 70 74 49 6e 74 65 |ude <Ope|nTptInte|
|000000b0| 72 6e 65 74 2e 68 3e 0d | 23 69 6e 63 6c 75 64 65 |rnet.h>.|#include|
|000000c0| 20 3c 45 76 65 6e 74 73 | 2e 68 3e 0d 23 69 6e 63 | <Events|.h>.#inc|
|000000d0| 6c 75 64 65 20 3c 73 74 | 64 69 6f 2e 68 3e 0d 23 |lude <st|dio.h>.#|
|000000e0| 69 6e 63 6c 75 64 65 20 | 3c 73 74 72 69 6e 67 2e |include |<string.|
|000000f0| 68 3e 0d 0d 73 74 61 74 | 69 63 20 55 49 6e 74 33 |h>..stat|ic UInt3|
|00000100| 32 20 67 4c 61 73 74 54 | 69 63 6b 73 20 3d 20 30 |2 gLastT|icks = 0|
|00000110| 3b 0d 0d 73 74 61 74 69 | 63 20 70 61 73 63 61 6c |;..stati|c pascal|
|00000120| 20 76 6f 69 64 20 4d 79 | 4e 6f 74 69 66 69 65 72 | void My|Notifier|
|00000130| 28 76 6f 69 64 2a 20 63 | 6f 6e 74 65 78 74 50 74 |(void* c|ontextPt|
|00000140| 72 2c 20 4f 54 45 76 65 | 6e 74 43 6f 64 65 20 63 |r, OTEve|ntCode c|
|00000150| 6f 64 65 2c 20 0d 09 09 | 09 09 09 09 09 09 09 20 |ode, ...|....... |
|00000160| 20 20 4f 54 52 65 73 75 | 6c 74 20 72 65 73 75 6c | OTResu|lt resul|
|00000170| 74 2c 20 76 6f 69 64 2a | 20 63 6f 6f 6b 69 65 29 |t, void*| cookie)|
|00000180| 0d 7b 0d 09 23 70 72 61 | 67 6d 61 20 75 6e 75 73 |.{..#pra|gma unus|
|00000190| 65 64 28 63 6f 6e 74 65 | 78 74 50 74 72 29 0d 09 |ed(conte|xtPtr)..|
|000001a0| 23 70 72 61 67 6d 61 20 | 75 6e 75 73 65 64 28 72 |#pragma |unused(r|
|000001b0| 65 73 75 6c 74 29 0d 09 | 23 70 72 61 67 6d 61 20 |esult)..|#pragma |
|000001c0| 75 6e 75 73 65 64 28 63 | 6f 6f 6b 69 65 29 0d 09 |unused(c|ookie)..|
|000001d0| 0d 09 73 77 69 74 63 68 | 20 28 63 6f 64 65 29 20 |..switch| (code) |
|000001e0| 7b 0d 09 09 63 61 73 65 | 20 6b 4f 54 53 79 6e 63 |{...case| kOTSync|
|000001f0| 49 64 6c 65 45 76 65 6e | 74 3a 0d 09 09 09 69 66 |IdleEven|t:....if|
|00000200| 20 28 20 54 69 63 6b 43 | 6f 75 6e 74 28 29 20 3e | ( TickC|ount() >|
|00000210| 20 67 4c 61 73 74 54 69 | 63 6b 73 20 2b 20 31 30 | gLastTi|cks + 10|
|00000220| 29 20 7b 0d 09 09 09 09 | 70 72 69 6e 74 66 28 22 |) {.....|printf("|
|00000230| 2e 22 29 3b 0d 09 09 09 | 09 66 66 6c 75 73 68 28 |.");....|.fflush(|
|00000240| 73 74 64 6f 75 74 29 3b | 0d 09 09 09 09 67 4c 61 |stdout);|.....gLa|
|00000250| 73 74 54 69 63 6b 73 20 | 3d 20 54 69 63 6b 43 6f |stTicks |= TickCo|
|00000260| 75 6e 74 28 29 3b 0d 09 | 09 09 7d 0d 09 09 09 62 |unt();..|..}....b|
|00000270| 72 65 61 6b 3b 0d 09 09 | 64 65 66 61 75 6c 74 3a |reak;...|default:|
|00000280| 0d 09 09 09 2f 2f 20 64 | 6f 20 6e 6f 74 68 69 6e |....// d|o nothin|
|00000290| 67 0d 09 09 09 62 72 65 | 61 6b 3b 0d 09 7d 0d 7d |g....bre|ak;..}.}|
|000002a0| 0d 0d 73 74 61 74 69 63 | 20 63 68 61 72 20 2a 67 |..static| char *g|
|000002b0| 48 54 54 50 53 65 72 76 | 65 72 20 3d 20 22 77 77 |HTTPServ|er = "ww|
|000002c0| 77 2e 73 74 61 69 72 77 | 61 79 73 2e 63 6f 6d 3a |w.stairw|ays.com:|
|000002d0| 38 30 22 3b 0d 73 74 61 | 74 69 63 20 63 68 61 72 |80";.sta|tic char|
|000002e0| 20 2a 67 47 65 74 48 54 | 54 50 43 6f 6d 6d 61 6e | *gGetHT|TPComman|
|000002f0| 64 20 3d 20 22 47 45 54 | 20 2f 20 48 54 54 50 2f |d = "GET| / HTTP/|
|00000300| 31 2e 30 5c 31 35 5c 31 | 32 5c 31 35 5c 31 32 22 |1.0\15\1|2\15\12"|
|00000310| 3b 0d 0d 76 6f 69 64 20 | 6d 61 69 6e 28 76 6f 69 |;..void |main(voi|
|00000320| 64 29 0d 7b 0d 09 45 6e | 64 70 6f 69 6e 74 52 65 |d).{..En|dpointRe|
|00000330| 66 20 65 70 3b 0d 09 4f | 53 53 74 61 74 75 73 20 |f ep;..O|SStatus |
|00000340| 65 72 72 3b 0d 09 54 43 | 61 6c 6c 20 63 6f 6e 6e |err;..TC|all conn|
|00000350| 65 63 74 43 61 6c 6c 3b | 0d 09 44 4e 53 41 64 64 |ectCall;|..DNSAdd|
|00000360| 72 65 73 73 20 63 6f 6e | 6e 65 63 74 41 64 64 72 |ress con|nectAddr|
|00000370| 3b 0d 09 4f 54 52 65 73 | 75 6c 74 20 62 79 74 65 |;..OTRes|ult byte|
|00000380| 73 53 65 6e 74 3b 0d 09 | 4f 54 52 65 73 75 6c 74 |sSent;..|OTResult|
|00000390| 20 62 79 74 65 73 52 65 | 63 65 69 76 65 64 3b 0d | bytesRe|ceived;.|
|000003a0| 09 63 68 61 72 20 63 68 | 3b 0d 09 4f 54 46 6c 61 |.char ch|;..OTFla|
|000003b0| 67 73 20 6a 75 6e 6b 46 | 6c 61 67 73 3b 0d 09 0d |gs junkF|lags;...|
|000003c0| 09 70 72 69 6e 74 66 28 | 22 48 65 6c 6c 6f 20 43 |.printf(|"Hello C|
|000003d0| 72 75 65 6c 20 57 6f 72 | 6c 64 21 5c 6e 22 29 3b |ruel Wor|ld!\n");|
|000003e0| 0d 09 0d 09 65 72 72 20 | 3d 20 49 6e 69 74 4f 70 |....err |= InitOp|
|000003f0| 65 6e 54 72 61 6e 73 70 | 6f 72 74 28 29 3b 0d 09 |enTransp|ort();..|
|00000400| 69 66 20 28 65 72 72 20 | 3d 3d 20 6e 6f 45 72 72 |if (err |== noErr|
|00000410| 29 20 7b 0d 09 09 65 70 | 20 3d 20 4f 54 4f 70 65 |) {...ep| = OTOpe|
|00000420| 6e 45 6e 64 70 6f 69 6e | 74 28 4f 54 43 72 65 61 |nEndpoin|t(OTCrea|
|00000430| 74 65 43 6f 6e 66 69 67 | 75 72 61 74 69 6f 6e 28 |teConfig|uration(|
|00000440| 22 4f 54 53 65 73 73 69 | 6f 6e 57 61 74 63 68 65 |"OTSessi|onWatche|
|00000450| 72 2c 74 63 70 22 29 2c | 20 30 2c 20 6e 69 6c 2c |r,tcp"),| 0, nil,|
|00000460| 20 26 65 72 72 29 3b 0d | 09 09 69 66 20 28 65 72 | &err);.|..if (er|
|00000470| 72 20 3d 3d 20 6e 6f 45 | 72 72 29 20 7b 0d 09 09 |r == noE|rr) {...|
|00000480| 09 28 76 6f 69 64 29 20 | 4f 54 53 65 74 53 79 6e |.(void) |OTSetSyn|
|00000490| 63 68 72 6f 6e 6f 75 73 | 28 65 70 29 3b 0d 09 09 |chronous|(ep);...|
|000004a0| 09 28 76 6f 69 64 29 20 | 4f 54 53 65 74 42 6c 6f |.(void) |OTSetBlo|
|000004b0| 63 6b 69 6e 67 28 65 70 | 29 3b 0d 09 09 09 28 76 |cking(ep|);....(v|
|000004c0| 6f 69 64 29 20 4f 54 55 | 73 65 53 79 6e 63 49 64 |oid) OTU|seSyncId|
|000004d0| 6c 65 45 76 65 6e 74 73 | 28 65 70 2c 20 74 72 75 |leEvents|(ep, tru|
|000004e0| 65 29 3b 0d 09 09 09 28 | 76 6f 69 64 29 20 4f 54 |e);....(|void) OT|
|000004f0| 49 6e 73 74 61 6c 6c 4e | 6f 74 69 66 69 65 72 28 |InstallN|otifier(|
|00000500| 65 70 2c 20 4d 79 4e 6f | 74 69 66 69 65 72 2c 20 |ep, MyNo|tifier, |
|00000510| 30 29 3b 0d 09 09 09 28 | 76 6f 69 64 29 20 4f 54 |0);....(|void) OT|
|00000520| 42 69 6e 64 28 65 70 2c | 20 6e 69 6c 2c 20 6e 69 |Bind(ep,| nil, ni|
|00000530| 6c 29 3b 0d 09 09 09 0d | 09 09 09 4f 54 4d 65 6d |l);.....|...OTMem|
|00000540| 7a 65 72 6f 28 26 63 6f | 6e 6e 65 63 74 43 61 6c |zero(&co|nnectCal|
|00000550| 6c 2c 20 73 69 7a 65 6f | 66 28 63 6f 6e 6e 65 63 |l, sizeo|f(connec|
|00000560| 74 43 61 6c 6c 29 29 3b | 0d 09 09 09 63 6f 6e 6e |tCall));|....conn|
|00000570| 65 63 74 43 61 6c 6c 2e | 61 64 64 72 2e 62 75 66 |ectCall.|addr.buf|
|00000580| 20 3d 20 28 55 49 6e 74 | 38 20 2a 29 20 26 63 6f | = (UInt|8 *) &co|
|00000590| 6e 6e 65 63 74 41 64 64 | 72 3b 0d 09 09 09 63 6f |nnectAdd|r;....co|
|000005a0| 6e 6e 65 63 74 43 61 6c | 6c 2e 61 64 64 72 2e 6c |nnectCal|l.addr.l|
|000005b0| 65 6e 20 3d 20 4f 54 49 | 6e 69 74 44 4e 53 41 64 |en = OTI|nitDNSAd|
|000005c0| 64 72 65 73 73 28 26 63 | 6f 6e 6e 65 63 74 41 64 |dress(&c|onnectAd|
|000005d0| 64 72 2c 20 67 48 54 54 | 50 53 65 72 76 65 72 29 |dr, gHTT|PServer)|
|000005e0| 3b 0d 09 09 09 0d 09 09 | 09 65 72 72 20 3d 20 4f |;.......|.err = O|
|000005f0| 54 43 6f 6e 6e 65 63 74 | 28 65 70 2c 20 26 63 6f |TConnect|(ep, &co|
|00000600| 6e 6e 65 63 74 43 61 6c | 6c 2c 20 6e 69 6c 29 3b |nnectCal|l, nil);|
|00000610| 0d 09 09 09 0d 09 09 09 | 69 66 20 28 65 72 72 20 |........|if (err |
|00000620| 3d 3d 20 6e 6f 45 72 72 | 29 20 7b 0d 09 09 09 09 |== noErr|) {.....|
|00000630| 62 79 74 65 73 53 65 6e | 74 20 3d 20 4f 54 53 6e |bytesSen|t = OTSn|
|00000640| 64 28 65 70 2c 20 67 47 | 65 74 48 54 54 50 43 6f |d(ep, gG|etHTTPCo|
|00000650| 6d 6d 61 6e 64 2c 20 73 | 74 72 6c 65 6e 28 67 47 |mmand, s|trlen(gG|
|00000660| 65 74 48 54 54 50 43 6f | 6d 6d 61 6e 64 29 2c 20 |etHTTPCo|mmand), |
|00000670| 30 29 3b 0d 09 09 09 09 | 69 66 20 28 20 62 79 74 |0);.....|if ( byt|
|00000680| 65 73 53 65 6e 74 20 3c | 20 30 20 29 20 7b 0d 09 |esSent <| 0 ) {..|
|00000690| 09 09 09 09 65 72 72 20 | 3d 20 62 79 74 65 73 53 |....err |= bytesS|
|000006a0| 65 6e 74 3b 0d 09 09 09 | 09 7d 0d 09 09 09 7d 0d |ent;....|.}....}.|
|000006b0| 09 09 09 69 66 20 28 65 | 72 72 20 3d 3d 20 6e 6f |...if (e|rr == no|
|000006c0| 45 72 72 29 20 7b 0d 09 | 09 09 09 64 6f 20 7b 0d |Err) {..|...do {.|
|000006d0| 09 09 09 09 09 62 79 74 | 65 73 52 65 63 65 69 76 |.....byt|esReceiv|
|000006e0| 65 64 20 3d 20 4f 54 52 | 63 76 28 65 70 2c 20 26 |ed = OTR|cv(ep, &|
|000006f0| 63 68 2c 20 31 2c 20 26 | 6a 75 6e 6b 46 6c 61 67 |ch, 1, &|junkFlag|
|00000700| 73 29 3b 0d 09 09 09 09 | 09 69 66 20 28 62 79 74 |s);.....|.if (byt|
|00000710| 65 73 52 65 63 65 69 76 | 65 64 20 3c 20 30 29 20 |esReceiv|ed < 0) |
|00000720| 7b 0d 09 09 09 09 09 09 | 65 72 72 20 3d 20 62 79 |{.......|err = by|
|00000730| 74 65 73 52 65 63 65 69 | 76 65 64 3b 0d 09 09 09 |tesRecei|ved;....|
|00000740| 09 09 7d 20 65 6c 73 65 | 20 7b 0d 09 09 09 09 09 |..} else| {......|
|00000750| 09 70 72 69 6e 74 66 28 | 22 25 63 22 2c 20 63 68 |.printf(|"%c", ch|
|00000760| 29 3b 0d 09 09 09 09 09 | 7d 0d 09 09 09 09 7d 20 |);......|}.....} |
|00000770| 77 68 69 6c 65 20 28 65 | 72 72 20 3d 3d 20 6e 6f |while (e|rr == no|
|00000780| 45 72 72 29 3b 0d 09 09 | 09 7d 0d 09 09 09 0d 09 |Err);...|.}......|
|00000790| 09 09 4f 54 43 6c 6f 73 | 65 50 72 6f 76 69 64 65 |..OTClos|eProvide|
|000007a0| 72 28 65 70 29 3b 0d 09 | 09 7d 0d 09 09 43 6c 6f |r(ep);..|.}...Clo|
|000007b0| 73 65 4f 70 65 6e 54 72 | 61 6e 73 70 6f 72 74 28 |seOpenTr|ansport(|
|000007c0| 29 3b 0d 09 7d 0d 09 0d | 09 69 66 20 28 65 72 72 |);..}...|.if (err|
|000007d0| 20 3d 3d 20 6e 6f 45 72 | 72 29 20 7b 0d 09 09 70 | == noEr|r) {...p|
|000007e0| 72 69 6e 74 66 28 22 53 | 75 63 63 65 73 73 21 5c |rintf("S|uccess!\|
|000007f0| 6e 22 29 3b 0d 09 7d 20 | 65 6c 73 65 20 7b 0d 09 |n");..} |else {..|
|00000800| 09 70 72 69 6e 74 66 28 | 22 46 61 69 6c 65 64 20 |.printf(|"Failed |
|00000810| 77 69 74 68 20 65 72 72 | 6f 72 20 25 64 2e 5c 6e |with err|or %d.\n|
|00000820| 22 2c 20 65 72 72 29 3b | 0d 09 7d 0d 09 70 72 69 |", err);|..}..pri|
|00000830| 6e 74 66 28 22 44 6f 6e | 65 2e 20 20 50 72 65 73 |ntf("Don|e. Pres|
|00000840| 73 20 63 6f 6d 6d 61 6e | 64 2d 51 20 74 6f 20 51 |s comman|d-Q to Q|
|00000850| 75 69 74 2e 5c 6e 22 29 | 3b 0d 7d 00 00 00 00 00 |uit.\n")|;.}.....|
|00000860| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000870| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000880| 00 00 01 00 00 00 01 54 | 00 00 00 54 00 00 00 46 |.......T|...T...F|
|00000890| 65 72 00 00 b9 70 72 6f | 74 54 79 70 65 00 07 96 |er...pro|tType...|
|000008a0| 68 61 6e 64 6c 65 72 00 | 06 b9 73 6f 63 6b 65 74 |handler.|..socket|
|000008b0| 09 45 78 61 6d 70 6c 65 | 2e 63 68 53 75 70 70 6f |.Example|.chSuppo|
|000008c0| 72 74 2e 70 69 65 73 74 | 69 73 63 6f 6e 2b 31 31 |rt.piest|iscon+11|
|000008d0| 02 00 54 45 58 54 43 57 | 49 45 01 00 ff ff ff ff |..TEXTCW|IE......|
|000008e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000008f0| 00 00 af db 2f 38 00 00 | 07 db 00 00 01 9a 74 42 |..../8..|......tB|
|00000900| 75 66 66 50 74 72 00 03 | 2c 72 65 74 42 75 66 66 |uffPtr..|,retBuff|
|00000910| 53 69 7a 65 00 00 a9 6d | 61 78 54 6f 47 65 74 00 |Size...m|axToGet.|
|00000920| 01 89 6e 75 6d 47 6f 74 | 74 65 6e 00 03 51 63 6f |..numGot|ten..Qco|
|00000930| 6e 66 69 72 6d 41 64 64 | 72 00 01 8b 6e 65 77 53 |nfirmAdd|r...newS|
|00000940| 6f 63 6b 65 74 00 07 6b | 66 69 6c 6c 65 72 34 00 |ocket..k|filler4.|
|00000950| 03 ae 6e 65 77 53 65 6c | 66 46 6c 61 67 00 03 1c |..newSel|fFlag...|
|00000960| 6f 6c 64 53 65 6c 66 46 | 6c 61 67 00 00 0f 6e 4b |oldSelfF|lag...nK|
|00000970| 69 6c 6c 51 45 6c 00 07 | 44 76 65 72 73 69 6f 6e |illQEl..|Dversion|
|00000980| 00 00 00 48 00 0a 47 65 | 6e 65 76 61 00 00 00 00 |...H..Ge|neva....|
|00000990| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000009a0| 00 00 00 00 00 00 00 02 | 00 02 00 2e 00 0a 02 f5 |........|........|
|000009b0| 02 8a 00 2e 00 0a 02 f5 | 02 8a b0 98 82 d9 00 00 |........|........|
|000009c0| 03 c0 00 00 03 d6 00 00 | 02 d9 01 00 00 00 00 04 |........|........|
|000009d0| 00 01 00 01 00 00 01 00 | 00 00 01 54 00 00 00 54 |........|...T...T|
|000009e0| 00 00 00 46 03 7e a2 d8 | 29 80 00 00 00 1c 00 46 |...F.~..|)......F|
|000009f0| 00 01 4d 50 53 52 00 00 | 00 12 4d 57 42 42 00 00 |..MPSR..|..MWBB..|
|00000a00| 00 1e 03 ed ff ff 00 00 | 00 00 00 00 00 00 03 f0 |........|........|
|00000a10| ff ff 00 00 00 4c 00 00 | 00 00 00 00 00 00 00 00 |.....L..|........|
|00000a20| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a30| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a40| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a50| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a60| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a70| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+